#ifndef PJAPIUA_H
#define PJAPIUA_H

#include "pjapiuaaccounthandler.h"

#ifdef __cplusplus
extern "C"{
#endif

#include <pjsua-lib/pjsua.h>
#include <pjsua-lib/pjsua_internal.h>

#ifdef __cplusplus
}
#endif

#include <string>

class PjApiUa
{
public:

    PjApiUa();

    ~PjApiUa();

    static PjApiUa *getInstance();

    void init();

    void start();

    void terminate();

    void registerAccountHandler(PjApiUaAccountHandler *handler);

    PjApiUaAccount *getUaAccount() const;

    PjApiUaAccountHandler *getUaAccountHandler() const;

    // To be refactored
    void setUaConfig(pjsua_config *config);

    void setLogConfig(pjsua_logging_config *config);

    void setMediaConfig(pjsua_media_config *config);
    //

    void setNullDevice();

    void setAccountConfig(const char *id,
                       const char *reg,
                       const char *proxy,
                       const char *username,
                       const char *password,
                       const char *realm);

    void setTransportConfig(pjsip_transport_type_e type, int port);

    void setMediaTransportConfig(int port);

    void setAutoAnswer(bool auto_answer);

private:



    void setCallback();

    //call back
    static void onIncomingCall(pjsua_acc_id acc_id, pjsua_call_id call_id,
			     pjsip_rx_data *rdata);

    static void onCallState(pjsua_call_id call_id, pjsip_event *e);

    static void onCallTsxState(pjsua_call_id call_id, pjsip_transaction *tsx, pjsip_event *e);

    static void onPager(pjsua_call_id call_id,
                    const pj_str_t *from,
                    const pj_str_t *to,
                    const pj_str_t *contact,
                    const pj_str_t *mime_type,
                    const pj_str_t *body);

    static void onTyping(pjsua_call_id call_id, const pj_str_t *from, const pj_str_t *to, const pj_str_t *contact, pj_bool_t is_typing);

    static pj_bool_t onStatelessRequest(pjsip_rx_data *rdata);

    static pj_status_t mod_handler_load(pjsip_endpoint *endpt);

    pjsua_config         m_uaConfig;

    pjsua_logging_config m_logConfig;

    pjsua_media_config   m_mediaConfig;

    pjsua_acc_config m_accountConfig;

    pjsua_transport_config m_transportConfig;

    pjsua_transport_config m_mediaTransportConfig;

    PjApiUaAccountHandler *m_accountHandler;

    bool m_autoAnswer;

    static PjApiUa *m_ua;

    static pjsip_module mod_default_handler;

    pj_pool_t *m_memPool;

};

#endif //PJAPIUA_H
